﻿using System;
using System.IO;
using KuaiPanSDK;
using KuaiPanSDK.Model;
using PHPLibrary;

namespace DemoSDk
{
    public partial class Demo : System.Web.UI.Page
    {
        private KuaiPan sdk = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            //sdk = new KuaiPan(Session["oauth_token"].ToString(), Session["oauth_token_secret"].ToString());
            sdk = new KuaiPan("556a38e8908d480b89f7a3904b36b62e", "0a2a7b443ffb4e4ab7b1575829128cd6");
        }

        protected void AccountInfo_Click(object sender, EventArgs e)
        {
            AccountInfo info = sdk.GetAccountInfo();
            if (info != null)
            {
                this.Result.Text = info.Data.Print();
                this.ToString.Text = info.ToString();
            }
            else
            {
                this.Result.Text = sdk.ErrMsg;
                this.ToString.Text = sdk.ErrMsg;
            }
        }

        protected void MetaData_Click(object sender, EventArgs e)
        {
            PHPArray arry = new PHPArray();
            MetaData metadata = sdk.GetMetaData("/", arry);
            if (metadata != null)
            {
                this.Result.Text = metadata.Data.Print();
                this.ToString.Text = metadata.ToString();
            }
            else
            {
                this.Result.Text = sdk.ErrMsg;
                this.ToString.Text = sdk.ErrMsg;
            }
        }

        protected void Shares_Click(object sender, EventArgs e)
        {
            Shares shares = sdk.GetShares("/logo1332117773.rar");
            if (shares != null)
            {
                this.Result.Text = shares.Data.Print();
                this.ToString.Text = shares.ToString();
            }
            else
            {
                this.Result.Text = sdk.ErrMsg;
                this.ToString.Text = sdk.ErrMsg;
            }
        }

        protected void Create_Click(object sender, EventArgs e)
        {
            Create create = sdk.Create("/logo1332117711173");
            if (create != null)
            {
                this.Result.Text = create.Data.Print();
                this.ToString.Text = create.ToString();
            }
            else
            {
                this.Result.Text = sdk.ErrMsg;
                this.ToString.Text = sdk.ErrMsg;
            }
        }

        protected void Delete_Click(object sender, EventArgs e)
        {
            Delete delete = sdk.Delete("/logo1332117711173", true);
            if (delete != null)
            {
                this.Result.Text = delete.Data.Print();
                this.ToString.Text = delete.ToString();
            }
            else
            {
                this.Result.Text = sdk.ErrMsg;
                this.ToString.Text = sdk.ErrMsg;
            }
        }

        protected void Move_Click(object sender, EventArgs e)
        {
            Move move = sdk.Move("/5.gif", "/7.gif");
            if (move != null)
            {
                this.Result.Text = move.Data.Print();
                this.ToString.Text = move.ToString();
            }
            else
            {
                this.Result.Text = sdk.ErrMsg;
                this.ToString.Text = sdk.ErrMsg;
            }
        }

        protected void Copy_Click(object sender, EventArgs e)
        {
            Copy copy = sdk.Copy("/5.gif", "/6.gif");
            if (copy != null)
            {
                this.Result.Text = copy.Data.Print();
                this.ToString.Text = copy.ToString();
            }
            else
            {
                this.Result.Text = sdk.ErrMsg;
                this.ToString.Text = sdk.ErrMsg;
            }
        }

        protected void Download_Click(object sender, EventArgs e)
        {
            string url = sdk.Download("/logo1332117773.rar");
            this.Result.Text = url;
            this.ToString.Text = url;
        }

        protected void UpLoadFile_Click(object sender, EventArgs e)
        {
            FileStream file = new FileStream(@"c:\5.gif", FileMode.Open);
            byte[] bb = new byte[file.Length];
            file.Read(bb, 0, (int)file.Length);
            file.Close();
            FileData filedata = sdk.UpLoadFile("/5.gif", true, "6.gif", bb);
            if (filedata != null)
            {
                this.Result.Text = filedata.Data.Print();
                this.ToString.Text = filedata.ToString();
            }
            else
            {
                this.Result.Text = sdk.ErrMsg;
                this.ToString.Text = sdk.ErrMsg;
            }

        }
    }
}